package com.zc.demo.aop;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Created by zhangchi9 on 2016/11/7.
 */
@Component
@Aspect
public class MagicianAnnotation implements MindReader{

    private String thoughts;

    /**
     * 定义参数化切点
     * @param thoughts
     */
    @Pointcut("execution(* com.zc.demo.aop.Thinker.thinkOfSomething(String)) && args(thoughts)")
    public void thinking(String thoughts){}

    /**
     * 把参数传递给通知
     * @param thoughts
     */
    @Before("thinking(thoughts)")
    @Override
    public void interceptThoughts(String thoughts) {
        System.out.println("注解拦截志愿者的想法"+thoughts);
        this.thoughts=thoughts;
    }

    @Override
    public String getThoughts() {
        return thoughts;
    }
}
